package ashok.corejava.threads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPools {
	public static void main(String[] args){
		ExecutorService executor = Executors.newFixedThreadPool(2);
		for(int i=0;i<5;i++){
			executor.submit(new MyProcessor(i));	
			
		}
			executor.shutdown();
			System.out.println("All Tasks submitted");
			try {
				executor.awaitTermination(10, TimeUnit.DAYS);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("All tasks completed");
	}
	
}

class MyProcessor implements Runnable{
	private int id;
	
	public MyProcessor(int id){
		this.id = id;
	}
	public void run(){
		System.out.println("Starting:"+ id);
		
		try{
			Thread.sleep(5000);
		}catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}